using System.Collections;
using System.Collections.Generic;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using UnityEngine;

public class KillStreakScrollView : MonoBehaviour
{
	public List<KillStreakImageFromScroll> listEventKillStreak = new List<KillStreakImageFromScroll>();

	public List<GameObject> listObject = new List<GameObject>();

	public UIScrollView scrollView;

	public static KillStreakScrollView init;

	public GameObject arrowLeft;

	public GameObject arrowRigth;

	public UICenterOnChild centerOnChild;

	private float scrollBack;

	public float moveScroll;

	private void Awake()
	{
		HOTween.Init();
		init = this;
	}

	private void OnDisable()
	{
		ClearKillStreak();
	}

	public void ScrollRight()
	{
		if (!(centerOnChild.centeredObject == null))
		{
			KillStreakImageFromScroll component = centerOnChild.centeredObject.GetComponent<KillStreakImageFromScroll>();
			if (listEventKillStreak.IndexOf(component) + 1 <= listEventKillStreak.Count - 1)
			{
				centerOnChild.CenterOn(listEventKillStreak[listEventKillStreak.IndexOf(component) + 1].transform);
			}
		}
	}

	public void ScrollLeft()
	{
		if (!(centerOnChild.centeredObject == null))
		{
			KillStreakImageFromScroll component = centerOnChild.centeredObject.GetComponent<KillStreakImageFromScroll>();
			if (listEventKillStreak.IndexOf(component) - 1 >= 0)
			{
				centerOnChild.CenterOn(listEventKillStreak[listEventKillStreak.IndexOf(centerOnChild.centeredObject.GetComponent<KillStreakImageFromScroll>()) - 1].transform);
			}
		}
	}

	public void CreateKillStreakImage()
	{
		if (GameplayRewardManager.instance.listKillStreakEvent.Count < 4)
		{
			arrowLeft.SetActive(false);
			arrowRigth.SetActive(false);
		}
		else
		{
			arrowLeft.SetActive(true);
			arrowRigth.SetActive(true);
		}
		foreach (GameplayRewardManager.KillStreak item in GameplayRewardManager.instance.listKillStreakEvent)
		{
			GameObject gameObject = Object.Instantiate(EndPVPWindow.instance.killStreakGO);
			KillStreakImageFromScroll component = gameObject.GetComponent<KillStreakImageFromScroll>();
			component.factor = item.number;
			component.nameSprite = NameSprite(item.reward, component.nameKill);
			component.nameKill.text = item.nameStreak;
			gameObject.transform.parent = base.transform;
			gameObject.transform.localPosition = Vector3.zero;
			gameObject.transform.localScale = Vector3.one;
			component.dragScrollView.scrollView = scrollView;
			listEventKillStreak.Add(component);
			listObject.Add(gameObject);
			component.SetPicture();
		}
		Invoke("Sort", 0.5f);
	}

	public void ClearKillStreak()
	{
		while (listObject.Count != 0)
		{
			Object.Destroy(listObject[0]);
			listObject.RemoveAt(0);
		}
		while (listEventKillStreak.Count != 0)
		{
			listEventKillStreak.RemoveAt(0);
		}
	}

	public IEnumerator ShowAllEvents()
	{
		Debug.Log("ShowAllEvents");
		for (int i = 0; i < listEventKillStreak.Count; i++)
		{
			if (i < listEventKillStreak.Count - 1)
			{
				centerOnChild.CenterOn(listEventKillStreak[i].transform);
			}
			listEventKillStreak[i].AnimationSprite();
			yield return new WaitForSeconds(0.6f);
		}
		if (listEventKillStreak.Count > 1)
		{
			centerOnChild.CenterOn(listEventKillStreak[1].transform);
		}
		else if (listEventKillStreak.Count > 0)
		{
			centerOnChild.CenterOn(listEventKillStreak[0].transform);
		}
		GameplayRewardManager.instance.ClearKillStreak();
		EndPVPWindow.instance.ShowStartAndMenu();
		yield return new WaitForSeconds(1f);
		Vector3 moveBack = Vector3.zero;
		float deltaBack = 0f;
		float prevBack = 0f;
		HOTween.To(this, 0.2f, new TweenParms().Prop("moveScroll", -1f * scrollBack).OnUpdate((TweenDelegate.TweenCallback)delegate
		{
			deltaBack = moveScroll - prevBack;
			moveBack.x = -1f * deltaBack;
			prevBack = moveScroll;
			scrollView.MoveRelative(moveBack);
		}));
		yield return null;
	}

	private void Sort()
	{
		GetComponent<UIGrid>().repositionNow = true;
		scrollView.MoveRelative(Vector3.left * 20f);
	}

	private string NameSprite(RewardMessages element, UILabel text)
	{
		string result;
		switch (element)
		{
		case RewardMessages.Headshoot:
			result = "Kill";
			text.color = new Color(1f, 0.149f, 0.149f, 1f);
			break;
		case RewardMessages.MultiKill:
			result = "Multikill";
			text.color = new Color(0.909f, 0.007f, 0.301f, 1f);
			break;
		case RewardMessages.Mincer:
			result = "Mincer";
			text.color = new Color(1f, 0.392f, 0.968f, 1f);
			break;
		case RewardMessages.CarKill:
			result = "Split";
			text.color = new Color(0.858f, 0.274f, 0f, 1f);
			break;
		case RewardMessages.BoomKill:
			result = "Boomkill";
			text.color = new Color(1f, 0.454f, 0f, 1f);
			break;
		case RewardMessages.VehicleGunKill:
			result = "VehicleGunKill";
			text.color = new Color(1f, 0.454f, 0f, 1f);
			break;
		case RewardMessages.DuckHunt:
			result = "Duckhunt";
			text.color = new Color(0.384f, 0f, 0.572f, 1f);
			break;
		case RewardMessages.JetShoot:
			result = "Jetshoot";
			text.color = new Color(1f, 0.941f, 0f, 1f);
			break;
		case RewardMessages.GhostKill:
			result = "Gostkill";
			text.color = new Color(1f, 0f, 0.462f, 1f);
			break;
		case RewardMessages.Revenge:
			result = "Revange";
			text.color = new Color(0.909f, 0.007f, 0.301f, 1f);
			break;
		case RewardMessages.SpawnKill:
			result = "Spaunkill";
			text.color = new Color(0.384f, 0f, 0.572f, 1f);
			break;
		case RewardMessages.Destruction:
			result = "Destruktion";
			text.color = new Color(1f, 0.454f, 0f, 1f);
			break;
		case RewardMessages.Driving:
			result = "Hightfly";
			text.color = new Color(0f, 0.396f, 1f, 1f);
			break;
		default:
			result = string.Empty;
			text.color = Color.white;
			break;
		}
		return result;
	}
}
